package james.edu.to;
import java.net.URL;

import javax.swing.ImageIcon;



public class FlashCardTO extends Entity{	
	
	protected String imageLocation;
	
	protected String description;
	
	protected ImageIcon image;
	
	protected boolean correct;
	
	protected boolean showPicture;
	
	protected boolean inactive = false;

	public FlashCardTO() {
		
	}
	
	public FlashCardTO(String location, String desc) {
		setImageLocation(location);
		setDescription(desc);
	}	   
	
	public boolean isCorrect() {
		return correct;
	}

	public void setCorrect(boolean correct) {
		this.correct = correct;
	}

	public ImageIcon getImage() {
		return image;
	}

	public void setImage(ImageIcon iamge) {
		this.image = iamge;
	}

	public boolean isShowPicture() {
		return showPicture;
	}

	public void setShowPicture(boolean showPicture) {
		this.showPicture = showPicture;
	}

	public boolean isInactive() {
		return inactive;
	}

	public void setInactive(boolean inactive) {
		this.inactive = inactive;
	}

	public String getImageLocation() {
		return imageLocation;
	}

	public void setImageLocation(String location) {
		if ((location.indexOf("http://") != -1)
				|| (location.indexOf("https://") != -1)) {
			try {
				URL url = new URL(location);
				this.image = new ImageIcon(url, this.getDescription());
				System.out.println("adding url: " + location);
			} catch (Exception e) {
				System.out.println("location: " + location
						+ "did not parse as a url");
			}
		} else {
			System.out.println("adding file: " + location);
			this.image = new ImageIcon(location, this.getDescription());
		}
		
		this.imageLocation = location;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		if(image == null) {
			image = new ImageIcon();
		}
		image.setDescription(description);
		this.description = description;
	}

}
